//
//  SelectExamLevelView.h
//  CommunityNannyO2O
//
//  Created by apple on 15/8/13.
//  Copyright (c) 2015年 Apple. All rights reserved.
//

#import "SelectExamLevelView.h"
#import "APIAdress.h"
#import "MBProgressHUD+YC.h"
#import "MJExtension.h"
#import "AccountTool.h"
#import "AppConfig.h"

@interface SelectExamLevelView()<UIPickerViewDataSource, UIPickerViewDelegate>
{

}
@property (weak, nonatomic) IBOutlet UIView *pickerBackgroundView;

@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;

@property (strong, nonatomic) NSMutableArray *aryData;

@property (assign, nonatomic) int selectedIndex;

@end

@implementation SelectExamLevelView

@synthesize aryData;

- (void)setLevelData:(NSMutableArray *)data
{
    self.aryData = data;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.pickerBackgroundView.layer.cornerRadius = 10.0;
    self.pickerBackgroundView.layer.borderColor = [UIColor clearColor].CGColor;
    self.pickerBackgroundView.layer.borderWidth = 0.0;
    
    self.pickerView.delegate = self;
    self.pickerView.dataSource = self;
    self.pickerView.backgroundColor = [UIColor clearColor];
    
    //手势
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap)];
    
    [self.view addGestureRecognizer:tapGestureRecognizer];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

-(NSInteger) pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    if (self.isMusicBase)
    {
        return 3;
    }
    return [self.aryData count];
}

-(NSString*) pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    if (self.isMusicBase)
    {
        NSString *title = [self.aryData objectAtIndex:row];
        
        if ([title isEqualToString:@"等级1"])
        {
            return @"初级";
        }
        else if ([title isEqualToString:@"等级2"])
        {
            return @"中级";
        }
        else if ([title isEqualToString:@"等级3"])
        {
            return @"高级";
        }
    }
    
    return [self.aryData objectAtIndex:row];
}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    self.selectedIndex = row;
}

-(void)tap
{
    if ([self.selectExamlevelDelegate respondsToSelector:@selector(setLevel:)]) {
        
        [self.selectExamlevelDelegate setLevel:[self.aryData objectAtIndex:self.selectedIndex]];
    }
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
    UILabel* pickerLabel = (UILabel*)view;
    if (!pickerLabel){
        pickerLabel = [[UILabel alloc] init];

        pickerLabel.adjustsFontSizeToFitWidth = YES;
        [pickerLabel setTextAlignment:NSTextAlignmentCenter];
        [pickerLabel setBackgroundColor:[UIColor clearColor]];
        [pickerLabel setFont:[UIFont fontWithName:@"Hiragino Sans GB" size:20]];
        pickerLabel.textColor = UIColorRGBA(19, 208, 202, 1);
    }
    // Fill the label text here
    pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
    
    return pickerLabel;
}

- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 68.0;
}

-(void)viewDidAppear:(BOOL)animated {
    [super viewDidAppear:animated];
    

}

- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
}


@end




















